package com.yunshang.shoppingmall.shopping.OrderController;

import com.yunshang.shoppingmall.Methods.FinaceMethods;
import com.yunshang.shoppingmall.common.MessageConstants;
import com.yunshang.shoppingmall.common.Response;
import com.yunshang.shoppingmall.entity.*;
import com.yunshang.shoppingmall.service.*;
import com.yunshang.shoppingmall.service.Finace.FinaceService;
import com.yunshang.shoppingmall.service.Finace.FinaceTotalService;
import com.yunshang.shoppingmall.service.User.UserRankService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.constraints.Min;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RequestMapping("/wap")
@Controller
public class PayOrderController {
    @Autowired
    OrderService orderService;

    @Autowired
    SysUserNoService sysUserNoService;

    @Autowired
    ConfigService configService;
    @Autowired
    FinaceService finaceService;
    @Autowired
    FinaceTotalService finaceTotalService;
    @Autowired
    UserRankService userRankService;
    @Autowired
    CartService cartService;
    @Autowired
    UserNoAchievementService userNoAchievementService;
    //订单支付-显示页面数据
    @ResponseBody
    @RequestMapping("/payOrder")
    public ModelAndView payOrder(HttpServletRequest request) {
        DecimalFormat df = new DecimalFormat("#0.00");//显示格式
        String orderNo = request.getParameter("No");//订单号
        Map<String, Object> map = new HashMap<>();
        HttpSession session = request.getSession();
        UserNo userNo1 = (UserNo) session.getAttribute("userNo");
        String name = "shoppingApi/order/pay";
        double freight = 0.00;//运费
        double totalPayMoney = 0.00;//订单需支付的总金额
        int memberUserId = 0;
        int memberLevel = 0;
        if (userNo1 != null) {
            memberUserId = userNo1.getId();
            memberLevel = userNo1.getRank();
            System.out.println(userNo1.toString()+"------------");
            if(userNo1.getPayPwd()!=null){
                if("".equals(userNo1.getPayPwd())){
                    map.put("paystate",false);
                }else {
                    map.put("paystate",true);
                }
            }else {
                map.put("paystate",false);
            }
        }else {
            name="shoppingApi/user/loginbypassword";
            ModelAndView modelAndView=new ModelAndView(name);
            return  modelAndView;
        }
        Order order = orderService.selectByNo(orderNo);//根据订单号查询订单
        if (order.getOrderStatus().equals("702")) {
            //
            //name="shoppingApi/user/memberCenter";
        }
        List<Cart> cartList =cartService.selectByOrderNo(orderNo);
        int buy=0;
        int guigeidT=0;
        if(cartList!=null&&cartList.size()>0){
            for (Cart cart:cartList) {
                int guigeid=cart.getGuigeId()==null?0:cart.getGuigeId();
                if(guigeid==536){
                    guigeidT=guigeid;
                }
                if(guigeid==352||guigeid==353||guigeid==354||guigeid==505){
                    buy=1;
                    break;
                }
//                if(guigeid==536){
//                    buy=2;
//                }
            }
        }
//        Double inter= FinaceMethods.getUserBalance(memberUserId,1).doubleValue();//积分
        /*查询用户的积分*/
        FinaceTotal finaceTotal = new FinaceTotal();
        finaceTotal.setfType("1");//积分
        finaceTotal.setUserId(memberUserId);

        Double inter = 0.00;
        FinaceTotal finaceTotals = FinaceMethods.selectFinaceBalace(finaceTotal);//积分
        if (finaceTotals != null) {
            inter = finaceTotals.getBalance();
        }

        Double inter1 = inter;
//        Double costinter=FinaceMethods.getUserBalance(memberUserId,4).doubleValue();//消费积分
        /*查询用户的消费积分*/
        finaceTotal.setfType("4");
        Double costinter = 0.00;
        FinaceTotal finaceTotals2 = FinaceMethods.selectFinaceBalace(finaceTotal);//消费积分
        if (finaceTotals2 != null) {
            costinter = finaceTotals2.getBalance();
        }
        //富贵酒活动不能使用消费积分
        if(guigeidT==536){
            costinter=0.00;
        }

        Double costinter1 = costinter;
        Config config1 = configService.selectByPrimaryKey(1);//货币名称显示
        Config cc=new Config();
        cc.setFinacename1(config1.getFinacename1());
        cc.setFinacename2(config1.getFinacename2());
        cc.setFinacename3(config1.getFinacename3());
        cc.setFinacename4(config1.getFinacename4());
        cc.setCashcouponmul(config1.getCashcouponmul());
        map.put("WebConfig", cc);
        map.put("buy", buy);
        map.put("order", order);
        map.put("inter", inter);//积分
        map.put("costinter", costinter);//消费积分
        map.put("rank", memberLevel);//
        ModelAndView modelAndView = new ModelAndView(name);
        modelAndView.addObject("orderPay", map);
        return modelAndView;
    }

    //订单支付
    @ResponseBody
    @RequestMapping("/pay")
    @Transactional()
    public Response pay(HttpServletRequest request) {
        HttpSession session = request.getSession();
        UserNo userNo1 = (UserNo) session.getAttribute("userNo");
        int memberUserId = 0,memberLevel = 0,ids = 0,userNoReCommendId=0;//推荐人id
        UserRank  userRank=null;
        UserRank recommendUserRank=null;//推荐人的等级
        UserNo recommendUserNo=null;
        int recommendRankId=0;
        double recommendCommission=0.00;

        if (userNo1 != null) {
            memberUserId = userNo1.getId();//用户编号ID
            memberLevel = userNo1.getRank();
            if(userNo1.getRecommend()!=null){
                if(userNo1.getRecommend()>0){
                    userNoReCommendId=userNo1.getRecommend();
                }else {
                    userNoReCommendId=62240;
                }
            }else {
                userNoReCommendId=62240;
            }
           userRank=userRankService.selectByPrimaryKey(memberLevel);//用户等级
            recommendUserNo=sysUserNoService.selectByPrimaryKey(userNoReCommendId);
            System.out.println("recommendUserNo:"+recommendUserNo.toString());
            if(recommendUserNo!=null){
                recommendRankId=recommendUserNo.getRank();
                recommendUserRank=userRankService.selectByPrimaryKey(recommendRankId);
                if(recommendUserRank!=null){
                    recommendCommission=recommendUserRank.getCommission();
                }
            }
        }
        Config config = configService.selectByPrimaryKey(1);//查询配置的信息
        Integer cashCouponMul = config.getCashcouponmul();//返折扣券的倍数 ---2倍
        String financeName = config.getFinacename3();//返回----折扣券的名称
        String id = request.getParameter("id");//订单id
        String costinter = request.getParameter("costinter");//消费积分
        String inter = request.getParameter("inter");//积分
        System.out.println("-------inter---------->" + inter);
        String cash = request.getParameter("cash");//微信现金支付金额
        Integer cashA = 0;
        double coupon = 0.00,costinterA = 0.00,interA = 0.00;
        if (cash != "" && cash != null) {
            cashA = Integer.parseInt(cash);//现金金额
        }
        if (costinter != null && costinter != "") {
            costinterA = Double.parseDouble(costinter);//消费积分
        }
        if (inter != "" && inter != null) {
            interA = Double.parseDouble(inter);//积分
        }
        System.out.println("积分：" + interA + "消费积分：" + costinterA);
        if (id != null && id != "") {
            ids = Integer.parseInt(id);
        }
        Order order = orderService.selectByPrimaryKey(ids);//根据Id查询订单
        String cartOrderNo=order.getCartOrderno()==null?"":order.getCartOrderno();
        if("".equals(cartOrderNo)){
            return new Response(MessageConstants.MSG_SYS_ERROR, -2, "购物车数据有误，请重新下单再试!");
        }
//        Double interUser= FinaceMethods.getUserBalance(memberUserId,1).doubleValue();//积分
        FinaceTotal finaceTotal = new FinaceTotal();
        finaceTotal.setfType("1");
        finaceTotal.setUserId(memberUserId);
        Double interUser = 0.00;
        FinaceTotal finaceTotals = FinaceMethods.selectFinaceBalace(finaceTotal);//积分

        int finace_id1=0;
        if (finaceTotals != null) {
            interUser = finaceTotals.getBalance();
            finace_id1=finaceTotals.getfId();
        }
        //推荐人积分
       double recommendBalance=0.00;
        int recommendFId=0;
        finaceTotal.setUserId(userNoReCommendId);
        finaceTotal.setfType("1");
        FinaceTotal recommendFinaceTotal = FinaceMethods.selectFinaceBalace(finaceTotal); //推荐人积分
        if(recommendFinaceTotal!=null){
            recommendFId=recommendFinaceTotal.getfId();
            recommendBalance=recommendFinaceTotal.getBalance();
        }

//        Double costinterUser=FinaceMethods.getUserBalance(memberUserId,4).doubleValue();//消费积分
        finaceTotal.setfType("4");
        finaceTotal.setUserId(memberUserId);
        Double costinterUser = 0.00;
        int finace_id4=0;
        FinaceTotal finaceTotals2 = FinaceMethods.selectFinaceBalace(finaceTotal);//消费积分

        if (finaceTotals2 != null) {
            costinterUser = finaceTotals2.getBalance();
            finace_id4=finaceTotals2.getfId();
        }

        //折扣券
        finaceTotal.setUserId(memberUserId);
        finaceTotal.setfType("3");
        double cashCoupon=0.00;//折扣券
        int finace_id3=0;
        FinaceTotal finaceTotals3 = FinaceMethods.selectFinaceBalace(finaceTotal);//折扣券
        if(finaceTotals3!=null){
            cashCoupon=finaceTotals3.getBalance();
            finace_id3=finaceTotals3.getfId();
        }
        //兑换券
        finaceTotal.setUserId(memberUserId);
        finaceTotal.setfType("2");
        double Coupon=0.00;//兑换券
        int finace_id2=0;
        FinaceTotal finaceTotals21 = FinaceMethods.selectFinaceBalace(finaceTotal);//兑换券
        if(finaceTotals21!=null){
            Coupon=finaceTotals21.getBalance();
            finace_id2=finaceTotals21.getfId();
        }
        if (order != null) {
            Double orderMoneyS = order.getRealPay().doubleValue() + order.getFreight().doubleValue();//订单需支付金额
            //System.out.println(interA+"--"+costinterA+"--"+cashA);
            Double moneyAll = Math.abs(interA + costinterA)+cashA;//支付金额
            Integer couponOrder=order.getCoupon()==null?0:order.getCoupon().intValue();//订单购物券
            Integer cashCouponOrder=order.getCashCoupon()==null?0:order.getCashCoupon().intValue();//订单代金券

            //System.out.println(moneyAll == orderMoneyS);
            //System.out.println("moneyAll:"+moneyAll+" orderMoneyS:"+orderMoneyS);
            if (!order.getOrderStatus().trim().equals("701")) {
                return new Response(MessageConstants.MSG_SYS_ERROR, -1, "订单状态有误!");
            } else if (Math.abs(costinterA) > costinterUser) {//消费积分
                return new Response(MessageConstants.MSG_SYS_ERROR, -1, "消费积分不足!");
            } else if (Math.abs(interA) > interUser) {//积分
                return new Response(MessageConstants.MSG_SYS_ERROR, -1, "积分不足!");
            }else if (Math.abs(couponOrder) > Coupon) {//购物券
                return new Response(MessageConstants.MSG_SYS_ERROR, -1, "购物券不足!");
            }else if (Math.abs(cashCouponOrder) > cashCoupon) {//代金券
                return new Response(MessageConstants.MSG_SYS_ERROR, -1, "代金券不足!");
            }else if (moneyAll.compareTo(orderMoneyS) != 0) {
                return new Response(MessageConstants.MSG_SYS_ERROR, -1, "订单金额与支付金额不一致!");
            } else {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date = new Date();
                String date1 = sdf.format(date);


                BigDecimal amount2=order.getCoupon()==null?BigDecimal.valueOf(0):(order.getCoupon());
                int res2s=0;
                if(amount2.doubleValue()>0){
                    FinaceToData finaceToData2 = new FinaceToData();
                    finaceToData2.setUserId(memberUserId);//用户编号Id
                    finaceToData2.setFinaceType("111");
                    finaceToData2.setRemark("支出"+order.getOrderNo());
                    finaceToData2.setClassify(2);
                    finaceToData2.setFinaceTime(Timestamp.valueOf(date1));//时间
                    double ss=-amount2.doubleValue();
                    finaceToData2.setAmount(new BigDecimal(ss));//
                    finaceToData2.setBalance(BigDecimal.valueOf(Coupon - amount2.doubleValue()));
                    finaceToData2.setOpratorUId(memberUserId);
                    res2s = finaceService.insertFinaceData(finaceToData2);
                    if(res2s<=0){
                        //购物券扣除有误
                        System.out.println("Classify2b");
                        Logger logger= LoggerFactory.getLogger("Classify2b"+order.getOrderNo());
                        //throw new RuntimeException();
                    }else {
                        //更新财务余额
                        FinaceTotal finaceTotal4=new FinaceTotal();
                        finaceTotal4.setfId(finace_id2);
                        finaceTotal4.setOpratorId(memberUserId);
                        finaceTotal4.setBalance((Coupon - amount2.doubleValue()));
                        finaceTotal4.setChanggeTime(new Timestamp(System.currentTimeMillis()));
                        finaceTotal4.setOpratorUId(memberUserId);
                        finaceTotal4.setUserId(memberUserId);
                        finaceTotal4.setfType("2");
                        int cosRow;
                        if(finace_id2>0){
                            cosRow =finaceTotalService.updateByPrimaryKeySelective(finaceTotal4);
                        }else {
                            cosRow =finaceTotalService.insertSelective(finaceTotal4);
                        }
                        if (cosRow <= 0) {
                            System.out.println("Classify2c");
                            //购物券扣除有误，支付失败!
                            //throw new RuntimeException();
                        }
                    }
                }

                FinaceToData finaceToData = new FinaceToData();
                finaceToData.setUserId(memberUserId);
                finaceToData.setFinaceType("111");
                finaceToData.setRemark("支出"+order.getOrderNo());
                finaceToData.setClassify(1);
//                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                Date date = new Date();
//                String date1 = sdf.format(date);
                finaceToData.setFinaceTime(Timestamp.valueOf(date1));//时间
                finaceToData.setAmount(BigDecimal.valueOf(interA));//积分

                //用户积分的余额
                finaceToData.setBalance(BigDecimal.valueOf(interUser - Math.abs(interA)));
                finaceToData.setOpratorUId(memberUserId);

                if (costinterA < 0) {//页面的传过来的参数为负数 ----消费积分
//                    Integer res=insertFinaceU(4,BigDecimal.valueOf(costinterA),memberUserId,order.getOrderNo()+"购物支付!",memberUserId,111);
//                    Integer res=insertFinaceU(4,BigDecimal.valueOf(costinterA),memberUserId,"支出",memberUserId,111);

                    finaceToData.setBalance(BigDecimal.valueOf(costinterUser-Math.abs(costinterA)));//消费积分余额
                    finaceToData.setAmount(BigDecimal.valueOf(costinterA));//支出金额
                    finaceToData.setClassify(4);
                    int res = finaceService.insertFinaceData(finaceToData);
                    //更新消费积分
                    FinaceTotal finaceTotal4=new FinaceTotal();
                    finaceTotal4.setfId(finace_id4);
                    finaceTotal4.setOpratorId(memberUserId);
                    finaceTotal4.setBalance(costinterUser-Math.abs(costinterA));
                    finaceTotal4.setAmount(costinterA);
                    finaceTotal4.setChanggeTime(new Timestamp(System.currentTimeMillis()));
                    finaceTotal4.setOpratorUId(memberUserId);
                    finaceTotal4.setUserId(memberUserId);
                    finaceTotal4.setfType("4");
                    int cosRow =finaceTotalService.updateByPrimaryKey(finaceTotal4);
                    if (cosRow <= 0) {
                        return new Response(MessageConstants.MSG_SYS_ERROR, -1, "消费积分扣除有误，支付失败!");
                    }
                }
                if (interA < 0) {//积分
//                    Integer res1=insertFinaceU(1,BigDecimal.valueOf(interA),memberUserId,order.getOrderNo()+"购物支付!",memberUserId,111);
//                    Integer res1=insertFinaceU(1,BigDecimal.valueOf(interA),memberUserId,"支出",memberUserId,111);
                    finaceToData.setClassify(1);
                    finaceToData.setBalance(new BigDecimal(interUser-Math.abs(interA)));
                    finaceToData.setAmount(new BigDecimal(interA));
                    System.out.println();
                    int row=0;
                    if(Math.abs(interA)>0){
                        row = finaceService.insertFinaceData(finaceToData);
                    }
                    //System.out.println("---更新积分--->"+row);
                    //添加推荐人的积分明细
                    //分享赚

                    double orderProfit=order.getOrderProfit();//订单利润
                    double shareEaring=0.00;
                if(recommendCommission-userRank.getCommission()>0){
                    shareEaring=orderProfit*(recommendCommission-userRank.getCommission())/100;
                }

                    //更新积分
                    FinaceTotal finaceTotal1=new FinaceTotal();
                    finaceTotal1.setOpratorId(memberUserId);
                    finaceTotal1.setBalance(interUser-Math.abs(interA));
                    finaceTotal1.setAmount(interA);
                    finaceTotal1.setChanggeTime(new Timestamp(System.currentTimeMillis()));
                    finaceTotal1.setOpratorUId(memberUserId);
                    finaceTotal1.setUserId(memberUserId);
                    finaceTotal1.setfType("1");
                    System.out.println("ss");
                    int f=0;
                    if(finace_id1>0){
                        finaceTotal1.setfId(finace_id1);
                        f=finaceTotalService.updateByPrimaryKey(finaceTotal1);
                    }else {
                        f=finaceTotalService.insertSelective(finaceTotal1);
                    }
                    if(f<=0){
                        return new Response(MessageConstants.MSG_SYS_ERROR, -1, "积分扣除有误，支付失败!");
                    }

                    if(userNoReCommendId<=0){//没有推荐人默认为零散会员编号id为62240
                        userNoReCommendId=62240;
                    }
                    if(userNoReCommendId>0){//是否有推荐人
                        if(shareEaring>0){
                            finaceToData.setBalance(new BigDecimal(shareEaring+recommendBalance));
                            finaceToData.setAmount(new BigDecimal(shareEaring));
                            finaceToData.setFinaceType("888");
                            finaceToData.setRemark("分享赚"+order.getOrderNo());
                            finaceToData.setUserId(userNoReCommendId);
                            finaceToData.setClassify(1);
                            int row1 = finaceService.insertFinaceData(finaceToData);

                            finaceTotal1.setOpratorId(memberUserId);
                            finaceTotal1.setBalance(recommendBalance+shareEaring);
                            finaceTotal1.setAmount(shareEaring);
                            finaceTotal1.setOpratorUId(memberUserId);
                            finaceTotal1.setUserId(userNoReCommendId);
                            finaceTotal1.setfType("1");
                            System.out.println("ss11");
                            int recommendF=0;
                            if(recommendFId>0){
                                finaceTotal1.setfId(recommendFId);
                                recommendF=finaceTotalService.updateByPrimaryKey(finaceTotal1);
                            }else{
                                finaceTotal1.setfId(0);
                                recommendF=finaceTotalService.insertSelective(finaceTotal1);
                            }
                            if(recommendF<=0){
                                return new Response(MessageConstants.MSG_SYS_ERROR, -1, "推荐人积分更新有误，支付失败!");
                            }
                        }

                    }
//                    if (row <= 0) {
//                        return new Response(MessageConstants.MSG_SYS_ERROR, -1, "积分扣除有误，支付失败!");
//                    }
                }
                order.setInter(new BigDecimal(Math.abs(interA)));
                order.setCostInter(new BigDecimal(Math.abs(costinterA)));
                order.setOrderStatus("702");
                order.setPayStatus("1");
                order.setPayTime(new Date());

                //返还折扣券保存到数据库返finance3_table
                int resf=0;
                if(cashCouponMul>0){
                    resf = FinaceMethods.insertFinaceU(3, BigDecimal.valueOf(order.getBackCashcoupon() * cashCouponMul), memberUserId, order.getOrderNo() + "返" + financeName, memberUserId, 999);
                }
                //更新折扣券
                FinaceTotal finaceTotal3=new FinaceTotal();
                finaceTotal3.setOpratorId(memberUserId);
                if(order.getCashCoupon()==null){
                    order.setCashCoupon(new BigDecimal(0));
                }
                System.out.println(cashCoupon+"---"+order.getCashCoupon().doubleValue());
                if(order.getCashCoupon().doubleValue()>0){
                    finaceTotal3.setBalance(cashCoupon-order.getCashCoupon().doubleValue());
                    //finaceTotal3.setAmount(order.getBackCashcoupon() * cashCouponMul);
                    finaceTotal3.setChanggeTime(new Timestamp(System.currentTimeMillis()));
                    finaceTotal3.setOpratorUId(memberUserId);
                    finaceTotal3.setUserId(memberUserId);
                    finaceTotal3.setfType("3");
                    int f=0;
                    System.out.println("------------折扣券s3------>"+finaceTotals3);
                    if(finaceTotals3!=null){
                        System.out.println("ss33");
                        finaceTotal3.setfId(finace_id3);
                        f =finaceTotalService.updateByPrimaryKeySelective(finaceTotal3);
                    }else{
                        f=finaceTotalService.insertSelective(finaceTotal3);
                    }

                    FinaceToData finaceToData2 = new FinaceToData();
                    finaceToData2.setUserId(memberUserId);//用户编号Id
                    finaceToData2.setFinaceType("111");
                    finaceToData2.setRemark("支出"+order.getOrderNo());
                    finaceToData2.setClassify(3);
                    finaceToData2.setFinaceTime(Timestamp.valueOf(date1));//时间
                    BigDecimal amount21=order.getCashCoupon();
                    finaceToData2.setAmount(new BigDecimal(-amount21.doubleValue()));//
                    finaceToData2.setBalance(BigDecimal.valueOf(cashCoupon - amount21.doubleValue()));
                    //finaceToData2.setOpratorUId(userNoId);
                    int res21 = finaceService.insertFinaceData(finaceToData2);
                }


               orderService.activity(order,memberUserId+"",userRank.getCommission(),userNoReCommendId);
                if (resf <= 0) {
                    //日志or数据库
                }
                //更新会员等级
                if (memberLevel == 19) {
                    userNo1.setRank(16);
//                  int resu=userNoService.updateByPrimaryKeySelective(userNo1);
                    int resu = sysUserNoService.updateByPrimaryKeySelective(userNo1);
                    if (resu <= 0) {
                        //日志or数据库
                    }
                }
                //添加记录运营成本到用户业绩表
                double opratorCost=0.00;//订单运营成本
                UserNoAchievement userNoAchievement=new UserNoAchievement();
                userNoAchievement.setOpratorCostSign("0");//为结算的业绩标志
                userNoAchievement.setUserNoId(memberUserId);
                userNoAchievement.setPayTime(new Timestamp(order.getpOrderTime().getTime()));
                if(order!=null&&order.getOpratorCost()!=null){
                    order.getOpratorCost().doubleValue();
                }
                if(order!=null&&order.getOpratorCost()!=null){
                    opratorCost=order.getOpratorCost().doubleValue();
                }

                userNoAchievement.setOrderId(order.getOrderId());
                userNoAchievement.setOrderOpratorCost(opratorCost);
                if(opratorCost>0) {
                    //int achievementRow = userNoAchievementService.insertSelective(userNoAchievement);
                    //添加记录运营成本到用户业绩表
                }
                Integer res2 = orderService.updateByPrimaryKeySelective(order);//更新订单状态
                if (res2 <= 0) {
                    return new Response(MessageConstants.MSG_SYS_ERROR, -1, "订单状态更新有误，支付失败!");
                }
                return new Response(MessageConstants.MSG_SUCCESS, order.getOrderNo(), "支付成功!");
            }
        } else {
            return new Response(MessageConstants.MSG_SYS_ERROR, 1, "订单有误，支付失败!");
        }
    }

    @ResponseBody
    @RequestMapping("/selectOrder")
    public Map<String, Object> selectOrder(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        String orderId = request.getParameter("orderId");
        int orderIds = 0;
        if (orderId != null && orderId != "") {
            orderIds = Integer.parseInt(orderId);
        }
        Order order = orderService.selectByPrimaryKey(orderIds);
        if (order != null) {
            map.put("order", order);
        }
        return map;
    }


}
